package com.toman.ui.work.workshop;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.example.zhouwei.library.CustomPopWindow;
import com.itheima.pulltorefreshlib.PullToRefreshBase;
import com.itheima.pulltorefreshlib.PullToRefreshScrollView;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;
import com.lzy.okhttputils.request.GetRequest;
import com.toman.Enum.BaseEnum;
import com.toman.Enum.NetworkEnum;
import com.toman.Enum.PermEnum;
import com.toman.Interfaces.NewBaseUrl;
import com.toman.JavaBean.SendworkorderEntity;
import com.toman.JavaBean.StaticsCount;
import com.toman.R;
import com.toman.Util.ActionCallback;
import com.toman.Util.BaseNetUtil;
import com.toman.Util.DialogUtils;
import com.toman.Util.IntentUtils;
import com.toman.Util.JsonExcludeNull;
import com.toman.Util.JsonUtils;
import com.toman.Util.PermissonUtils;
import com.toman.Util.StringUtils;
import com.toman.Util.ToastUtil;
import com.toman.Util.ViewUtil;
import com.toman.bean.DialogBean;
import com.toman.toolbar.ToolBarActivity;
import com.toman.widget.ClearEditText;
import com.toman.widget.CommonAdapterNew;
import com.toman.widget.callback.StringLoadingCallback;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Request;
import okhttp3.Response;

public class DispatchingActivity extends ToolBarActivity {

    @BindView(R.id.et_search)
    ClearEditText etSearch;
    @BindView(R.id.tv_select)
    TextView tvSelect;
    @BindView(R.id.fl_et)
    RelativeLayout flEt;
    @BindView(R.id.tv_select0)
    TextView tvSelect0;
    @BindView(R.id.iv_select0)
    ImageView ivSelect0;
    @BindView(R.id.rl_select0)
    RelativeLayout rlSelect0;
    @BindView(R.id.tv_select1)
    TextView tvSelect1;
    @BindView(R.id.iv_select1)
    ImageView ivSelect1;
    @BindView(R.id.rl_select1)
    RelativeLayout rlSelect1;
    @BindView(R.id.tv_select2)
    TextView tvSelect2;
    @BindView(R.id.iv_select2)
    ImageView ivSelect2;
    @BindView(R.id.rl_select2)
    RelativeLayout rlSelect2;
    @BindView(R.id.tv_select3)
    TextView tvSelect3;
    @BindView(R.id.iv_select3)
    ImageView ivSelect3;
    @BindView(R.id.rl_select3)
    RelativeLayout rlSelect3;
    @BindView(R.id.ll_base)
    LinearLayout llBase;
    @BindView(R.id.cb_muti)
    CheckBox cbMuti;
    @BindView(R.id.btn_muti)
    Button btnMuti;
    @BindView(R.id.rl_muti)
    RelativeLayout rlMuti;
    @BindView(R.id.lv)
    RecyclerView lv;
    @BindView(R.id.mPullToRefreshScrollView)
    PullToRefreshScrollView mPullToRefreshScrollView;
    @BindView(R.id.mMangeNodata)
    TextView mMangeNodata;
    int page = 2;
    private List<SendworkorderEntity> list = new ArrayList<>();
    Dialog dialog;
    private String auditStatus="0";
    private String orderStatus="";
    private String status="0";
    private String planId = "";

    CommonAdapterNew<SendworkorderEntity> adapter;
    private CustomPopWindow mCustomPopWindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dispatching);
        ButterKnife.bind(this);
        initToolBar(BaseEnum.DISPATCHING.name);
        initIntent();
        initView();
    }

    private void initIntent() {

        planId = getIntent().getStringExtra("planId");
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (!StringUtils.isEmpty(getIntent().getStringExtra("status"))){
            p_id=(getIntent().getStringExtra("etSearch"));
            setStatus(getIntent().getStringExtra("status"));
        } else {
            customer(1, 1, etSearch.getText().toString());
        }

    }
    private void initView() {
        baseEnum=BaseEnum.DISPATCHING;
        ViewUtil.permission(getApplicationContext(), BaseEnum.DISPATCHING.has(PermEnum.CHECK), rlMuti);
        etSearch.setHint("派工单号/品号/品名");

        initAdapter();
        cbMuti.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

                for (int i = 0; i < list.size(); i++) {
                list.get(i).setCheckStatus(b);
            }


                adapter.notifyDataSetChanged();
        }
        });
        rlMuti.setVisibility(View.GONE);
        adapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                List<SendworkorderEntity> beanlist = adapter.getDatas();
                SendworkorderEntity  bean=beanlist.get(position);
                Bundle bundle = new Bundle();
                bundle.putSerializable("bean", bean);
                bundle.putString("status", status);
                IntentUtils.startActivity(DispatchingActivity.this, DispatchingInfActivity.class, bundle);
            }
            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
        lv.setAdapter(adapter);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        lv.setLayoutManager(manager);
        mPullToRefreshScrollView.setMode(PullToRefreshBase.Mode.BOTH);
        mPullToRefreshScrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                dialog=null;
                p_id=null;

                dialogList.clear();
                page = 2;
                customer(1, 1, etSearch.getText().toString().trim());
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                customer(page, 2, etSearch.getText().toString().trim());
                page += 1;
            }
        });
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) { }
            @Override
            public void afterTextChanged(Editable s) {
                customer(1, 1, s.toString().trim());
            }
        });

    }

    private void initAdapter() {
        adapter = new CommonAdapterNew<SendworkorderEntity>(this, R.layout.item_workshop_dispatching, list) {
            @Override
            protected void convert(ViewHolder holder, SendworkorderEntity item, final int position) {
                holder.setText(R.id.tv_time,item.getCreateTime());
                holder.setText(R.id.tv_code,item.getSendworkCode());
                holder.setText(R.id.tv_plan_code,item.getPlanEntity().getPlanNum());
                holder.setText(R.id.tv_no,item.getProductEntity().getProductName());
                holder.setText(R.id.tv_beltline,item.getOperationArtlineEntity().getArtlineName());
                holder.setText(R.id.tv_dispatching,item.getSendworkCount()+"");
                holder.setText(R.id.tv_finish,item.getSendworkStaticsCount().getCompletedCount()+"");
                holder.getView(R.id.btn_del).setOnClickListener(v -> BaseNetUtil.actionDialog(DispatchingActivity.this, NewBaseUrl.workshop_sendworkorder_delete, item.getId() + "", token, "删除"+BaseEnum.DISPATCHING.name, () -> customer(1, 1, etSearch.getText().toString())));
                holder.getView(R.id.btn_continue).setOnClickListener(v -> BaseNetUtil.actionDialog(DispatchingActivity.this, NewBaseUrl.workshop_sendworkorder_updateStatusContinue, item.getId() + "", token, "继续"+BaseEnum.DISPATCHING.name, () -> customer(1, 1,etSearch.getText().toString())));
                holder.getView(R.id.btn_finish).setOnClickListener(v -> BaseNetUtil.actionDialog(DispatchingActivity.this, NewBaseUrl.workshop_sendworkorder_updateStatusEnd, item.getId() + "", token, "结束"+BaseEnum.DISPATCHING.name, () -> customer(1, 1, etSearch.getText().toString())));
                holder.getView(R.id.btn_pause).setOnClickListener(v -> BaseNetUtil.actionDialog(DispatchingActivity.this, NewBaseUrl.workshop_sendworkorder_updateStatusPause, item.getId() + "", token, "暂停"+BaseEnum.DISPATCHING.name, () -> customer(1, 1, etSearch.getText().toString())));
                holder.getView(R.id.btn_look_first).setOnClickListener(v -> lookFirst(item));
                holder.getView(R.id.btn_look_more).setOnClickListener(v -> lookMore(item));
                CheckBox checkBox=  holder.getView(R.id.cb_status);
                checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> item.setCheckStatus(isChecked));
//                待审核
                if (item.getAuditStatus().equals("0")){

                    checkBox.setChecked(item.getCheckStatus());
                    checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> item.setCheckStatus(isChecked));
                    holder.getView(R.id.btn_check).setOnClickListener(v -> mutiCheckDialog(item.getId()+""));
                    holder.getView(R.id.cb_status).setVisibility(View.VISIBLE);
                    holder.getView(R.id.btn_del).setVisibility(View.VISIBLE);
                    holder.getView(R.id.btn_check).setVisibility(View.VISIBLE);
                    holder.getView(R.id.btn_more).setVisibility(View.GONE);
                    holder.getView(R.id.btn_pause).setVisibility(View.GONE);
                    holder.getView(R.id.btn_continue).setVisibility(View.GONE);
                    holder.getView(R.id.btn_finish).setVisibility(View.GONE);
                    holder.getView(R.id.btn_look_first).setVisibility(View.GONE);
                    holder.getView(R.id.btn_look_more).setVisibility(View.GONE);
                }
//                进行中
                else if(item.getOrderStatus().equals("0")){
                    holder.getView(R.id.cb_status).setVisibility(View.GONE);
                    holder.getView(R.id.btn_del).setVisibility(View.GONE);
                    holder.getView(R.id.btn_check).setVisibility(View.GONE);
                    holder.getView(R.id.btn_more).setVisibility(View.VISIBLE);
                    if (position+1==list.size()){
                        holder.getView(R.id.btn_more).setOnClickListener(v -> showPopMenu((Button) v, item,true));
                    }
                    else {
                        holder.getView(R.id.btn_more).setOnClickListener(v -> showPopMenu((Button) v, item,false));

                    }
                    holder.getView(R.id.btn_pause).setVisibility(View.VISIBLE);
                    holder.getView(R.id.btn_continue).setVisibility(View.GONE);
                    holder.getView(R.id.btn_finish).setVisibility(View.VISIBLE);
                    holder.getView(R.id.btn_look_first).setVisibility(View.GONE);
                    holder.getView(R.id.btn_look_more).setVisibility(View.GONE);
                }
//                已暂停
                else if(item.getOrderStatus().equals("1")){
                    holder.getView(R.id.cb_status).setVisibility(View.GONE);
                    holder.getView(R.id.btn_del).setVisibility(View.GONE);
                    holder.getView(R.id.btn_check).setVisibility(View.GONE);
                    holder.getView(R.id.btn_more).setVisibility(View.VISIBLE);
                    if (position+1==list.size()){
                        holder.getView(R.id.btn_more).setOnClickListener(v -> showPopMenu((Button) v, item,true));
                    }
                    else {
                        holder.getView(R.id.btn_more).setOnClickListener(v -> showPopMenu((Button) v, item,false));

                    }

                    holder.getView(R.id.btn_pause).setVisibility(View.GONE);
                    holder.getView(R.id.btn_continue).setVisibility(View.VISIBLE);
                    holder.getView(R.id.btn_finish).setVisibility(View.VISIBLE);
                    holder.getView(R.id.btn_look_first).setVisibility(View.GONE);
                    holder.getView(R.id.btn_look_more).setVisibility(View.GONE);
                }
//                已结束
                else if(item.getOrderStatus().equals("2")){
                    holder.getView(R.id.cb_status).setVisibility(View.GONE);
                    holder.getView(R.id.btn_del).setVisibility(View.VISIBLE);
                    holder.getView(R.id.btn_check).setVisibility(View.GONE);
                    holder.getView(R.id.btn_more).setVisibility(View.GONE);
                    holder.getView(R.id.btn_pause).setVisibility(View.GONE);
                    holder.getView(R.id.btn_continue).setVisibility(View.GONE);
                    holder.getView(R.id.btn_finish).setVisibility(View.GONE);
                    holder.getView(R.id.btn_look_first).setVisibility(View.VISIBLE);
                    holder.getView(R.id.btn_look_more).setVisibility(View.VISIBLE);
                }
                ViewUtil.permission(getApplicationContext(), BaseEnum.DISPATCHING.has(PermEnum.CHECK), holder.getView(R.id.btn_check));
                ViewUtil.permission(getApplicationContext(), BaseEnum.DISPATCHING.has(PermEnum.DELETE), holder.getView(R.id.btn_del));
                ViewUtil.permission(getApplicationContext(), BaseEnum.DISPATCHING.has(PermEnum.PAUSEWORK), holder.getView(R.id.btn_pause));
                ViewUtil.permission(getApplicationContext(), BaseEnum.DISPATCHING.has(PermEnum.ENDWORK), holder.getView(R.id.btn_finish));
                ViewUtil.permission(getApplicationContext(), BaseEnum.DISPATCHING.has(PermEnum.CONTINUEWORK), holder.getView(R.id.btn_continue));

                if (!PermissonUtils.contains(getApplicationContext(), BaseEnum.DISPATCHING.has(PermEnum.CHECK))) {
                    holder.getView(R.id.cb_status).setVisibility(View.GONE);
                }

            }
        };
    }
    private void showPopMenu(Button button, SendworkorderEntity entity, boolean isBottom){
        View contentView = LayoutInflater.from(this).inflate(R.layout.pop_menu_dispatching,null);
        //处理popWindow 显示内容
        View view = contentView.findViewById(R.id.menu3);
        ViewUtil.permission(getApplicationContext(), BaseEnum.DISPATCHING.has(PermEnum.DELETE), view);

        handleLogic(contentView,entity);
        //创建并显示popWindow
        mCustomPopWindow= new CustomPopWindow.PopupWindowBuilder(this)
                .setView(contentView)
                .create();
        if (isBottom){
            mCustomPopWindow.showAsDropDown(button,0,-240);
        }
        else {
            mCustomPopWindow .showAsDropDown(button,0,20);

        }


    }

    private void handleLogic(View contentView,SendworkorderEntity entity){
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mCustomPopWindow!=null){
                    mCustomPopWindow.dissmiss();
                }
                switch (v.getId()){
                    case R.id.menu1:
                        lookFirst(entity);
                        break;
                    case R.id.menu2:
                        lookMore(entity);
                        break;
                    case R.id.menu3:
                        BaseNetUtil.actionDialog(DispatchingActivity.this, NewBaseUrl.workshop_sendworkorder_delete, entity.getId() + "", token, "删除"+BaseEnum.DISPATCHING.name, () -> customer(1, 1, etSearch.getText().toString()));
                        break;

                }
            }
        };
        contentView.findViewById(R.id.menu1).setOnClickListener(listener);
        contentView.findViewById(R.id.menu2).setOnClickListener(listener);
        contentView.findViewById(R.id.menu3).setOnClickListener(listener);
    }

    private void lookMore(SendworkorderEntity entity) {
        Bundle bundle = new Bundle();
        bundle.putString("isfirstReport", "0");
        bundle.putString("status", "1");
        bundle.putString("sendworkId", entity.getId() + "");
        IntentUtils.startActivity(DispatchingActivity.this, SubmitActivity.class, bundle);
    }

    private void lookFirst(SendworkorderEntity entity) {
        Bundle bundle = new Bundle();
        bundle.putString("status", "1");
        bundle.putString("isfirstReport", "1");
        bundle.putString("sendworkId", entity.getId() + "");
        IntentUtils.startActivity(DispatchingActivity.this, SubmitActivity.class, bundle);
    }

    public void customer(Integer page, final Integer type, String search) {
        if (dialog!=null){
            dialog.dismiss();
        }


        GetRequest params = OkHttpUtils
                .get(NewBaseUrl.workshop_sendworkorder_list)
                .params("token", token)
                .params("key", search)
                .params("limit", NewBaseUrl.num)
                .params("page", page.toString())
                .params("auditStatus", auditStatus)
                .params("orderStatus", orderStatus)
                .params("planId", planId)
                .params("id",p_id)

                ;
        for (DialogBean bean: dialogList){
            params.params(bean.getSubmitName(),bean.getResult());
        }
        params  .execute(new StringLoadingCallback(this,mPullToRefreshScrollView,search){
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "派工信息列表: " + result);
                        if (type == 1) {
                            list.clear();
                        }
                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,getApplicationContext());
                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");

                            List<SendworkorderEntity> jsonArray = new ArrayList<SendworkorderEntity>(JsonExcludeNull.parseArrayExcludeNull(Jpage.getString("list"), SendworkorderEntity.class));
                            list.addAll(jsonArray);

                            if (list.size() == 0) {
                                mMangeNodata.setVisibility(View.VISIBLE);
                            } else {
                                mMangeNodata.setVisibility(View.GONE);
                            }
                            adapter.notifyDataSetChanged(3);
                            StaticsCount count = JSON.parseObject(Jpage.getString("staticsCount"), new TypeReference<StaticsCount>() {
                            });
                            tvSelect0.setText("待审核(" + count.getCount0() + ")");
                            tvSelect1.setText("进行中(" + count.getCount1() + ")");
                            tvSelect2.setText("已暂停(" + count.getCount2() + ")");
                            tvSelect3.setText("已结束(" + count.getCount3() + ")");
                            setCbMuti();
                        } else {
                            ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
                        }

                        mPullToRefreshScrollView.onRefreshComplete();
                    }
                });
    }

    private void setStatus(String status){
        this.status=status;
        switch (status){
            case "0":
                auditStatus="0";
                orderStatus="";
                tvSelect0.setTextColor(getResources().getColor(R.color.button_blue));
                tvSelect1.setTextColor(getResources().getColor(R.color.black33));
                tvSelect2.setTextColor(getResources().getColor(R.color.black33));
                tvSelect3.setTextColor(getResources().getColor(R.color.black33));
                ivSelect0.setBackgroundColor(getResources().getColor(R.color.button_blue));
                ivSelect1.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect2.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect3.setBackgroundColor(getResources().getColor(R.color.white));
                customer(1, 1, etSearch.getText().toString());
                break;
            case "1":
                auditStatus="";
                orderStatus="0";
                tvSelect1.setTextColor(getResources().getColor(R.color.button_blue));
                tvSelect2.setTextColor(getResources().getColor(R.color.black33));
                tvSelect3.setTextColor(getResources().getColor(R.color.black33));
                tvSelect0.setTextColor(getResources().getColor(R.color.black33));
                ivSelect1.setBackgroundColor(getResources().getColor(R.color.button_blue));
                ivSelect2.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect3.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect0.setBackgroundColor(getResources().getColor(R.color.white));


                customer(1, 1, etSearch.getText().toString());
                break;
            case "2":
                auditStatus="";
                orderStatus="1";
                tvSelect2.setTextColor(getResources().getColor(R.color.button_blue));
                tvSelect1.setTextColor(getResources().getColor(R.color.black33));
                tvSelect0.setTextColor(getResources().getColor(R.color.black33));
                tvSelect3.setTextColor(getResources().getColor(R.color.black33));
                ivSelect2.setBackgroundColor(getResources().getColor(R.color.button_blue));
                ivSelect1.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect0.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect3.setBackgroundColor(getResources().getColor(R.color.white));

                customer(1, 1, etSearch.getText().toString());


                break;
            case "3":
                auditStatus="";
                orderStatus="2";
                tvSelect3.setTextColor(getResources().getColor(R.color.button_blue));
                tvSelect1.setTextColor(getResources().getColor(R.color.black33));
                tvSelect0.setTextColor(getResources().getColor(R.color.black33));
                tvSelect2.setTextColor(getResources().getColor(R.color.black33));
                ivSelect3.setBackgroundColor(getResources().getColor(R.color.button_blue));
                ivSelect1.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect0.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect2.setBackgroundColor(getResources().getColor(R.color.white));
                customer(1, 1, etSearch.getText().toString());


                break;

        }
    }


    public void setSelect(String select) {
        switch (select) {
            case "0":
                setStatus("0");
                break;
            case "1":
                setStatus("1");
                break;
            case "2":
                setStatus("1");
                break;
            case "3":
                setStatus("2");
                break;
            case "4":
                setStatus("1");
                break;
            case "5":
                setStatus("3");
                break;
        }
    }
    private void setCbMuti(){
        cbMuti.setChecked(false);

        switch (status){
            case "0":
                btnMuti.setText("一键审核");
                if (PermissonUtils.contains(this, baseEnum.has(PermEnum.CHECK))&&list.size()!=0){
                    rlMuti.setVisibility(View.VISIBLE);
                }
                break;

            default:
                rlMuti.setVisibility(View.GONE);
        }

    }

    public void mutiCheckDialog(final String ids) {

        //LayoutInflater是用来找layout文件夹下的xml布局文件，并且实例化

        new AlertDialog.Builder(this)
                //对话框的标题
                .setTitle("确认审核选中的派工信息吗？")
                //设定显示的View
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", (dialog, whichButton) -> check(ids))
                .setNegativeButton("取消", (dialog, which) -> {

                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create().show();

    }
    public void mutiCheckDialogNew(final String ids) {

        //LayoutInflater是用来找layout文件夹下的xml布局文件，并且实例化

        new AlertDialog.Builder(this)
                //对话框的标题
                .setTitle("确认一键审核选中的派工信息吗？")
                //设定显示的View
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", (dialog, whichButton) -> check(ids))
                .setNegativeButton("取消", (dialog, which) -> {

                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create().show();

    }
    private void check( String ids) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("ids", ids );
        String str = JsonUtils.obj2JsonString(map);
        OkHttpUtils
                .post(NewBaseUrl.workshop_sendworkorder_verify +ids)
                .headers("token", token)
                .postJson(str)
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "审核派工信息: " + result);
                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,getApplicationContext());

                        if (code == 0) {
                            ToastUtil.makeText(getApplicationContext(), jsonObj.getString("msg"));
                            customer(1, 1, "");


                        } else {
                            ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
                        }

                    }
                });
    }

    private String getMutiCheck() {
        StringBuilder stringBuffer = new StringBuilder();

        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getCheckStatus()) {
                if (stringBuffer.length() <= 0) {
                    stringBuffer.append(list.get(i).getId());
                } else {
                    stringBuffer.append(",").append(list.get(i).getId());
                }
            }

        }
        if (stringBuffer.length() <= 0) {
            return null;
        } else {
            return stringBuffer.toString();
        }

    }



    @OnClick({R.id.tv_select,R.id.rl_select0, R.id.rl_select1, R.id.rl_select2, R.id.rl_select3, R.id.btn_muti})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_select0:
                setStatus("0");
                break;
            case R.id.rl_select1:
                setStatus("1");
                break;
            case R.id.rl_select2:
                setStatus("2");
                break;
            case R.id.rl_select3:
                setStatus("3");
                break;
            case R.id.btn_muti:
                if (getMutiCheck()==null){
                    ToastUtil.makeText(getApplicationContext(),"请至少选中一个选项");
                }
                else {
                    mutiCheckDialogNew(getMutiCheck());
                }
                break;
            case R.id.tv_select:
                showDialog();
                break;
        }
    }

    public void showDialog() {
        if (dialog == null) {
            dialogList.clear();
            dialogList.add( new DialogBean("productId","品名", 1, BaseNetUtil.base(this, NetworkEnum.PRODUCT, mCompanyId)));
            dialogList.add( new DialogBean("artlineId","工艺路线名称", 1, BaseNetUtil.base(this, NetworkEnum.ARTLINE, mCompanyId)));
            dialogList.add( new DialogBean("beltlineId","产线名称", 1, BaseNetUtil.base(this, NetworkEnum.BELTLINE, mCompanyId)));


            dialog = DialogUtils.selectNewDialog(this, dialogList, new ActionCallback() {
                @Override
                public void run() {
                    customer(1, 1,"");
                    dialog.dismiss();

                }
            });
            dialog.show();
        } else {
            dialog.show();
        }
    }
}
